<?php
/**
 * 网站配置
 * Class ConfigControl
 */
class ConfigControl extends CommonControl{
    public function index()
    {
        $db = M("config");
        $config = $db->all();
        $this->assign("config", $config);
        $this->display();
    }

    public function edit()
    {
        $db = M("config");
        $db->save($_POST['config']);
        $config =array();
        foreach($_POST['config'] as $c){
            $config[$c['name']]=$c['value'];
        }
        $config="<?php if(!defined('HDPHP_PATH'))exit;\n return ".var_export($config,true).";\n?>";
        file_put_contents(CONFIG_PATH.'/base.config.php',$config);
        $this->success('修改配置项成功', "index");
    }
}